package article

import (
	"gohub/app/models"
	"gohub/pkg/database"
)

// Article 模型
type Article struct {
	models.BaseModel

	Title       string `json:"title,omitempty"`
	Author      string `json:"author,omitempty"`
	Content     string `json:"content,omitempty"`
	Desc        string `json:"desc,omitempty"`
	Ranking     int    `json:"ranking,omitempty"`
	PublishDate string `json:"publishDate,omitempty"`

	models.CommonTimestampsField
}

// Create 创建，通过 Article.ID 来判断是否创建成功
func (articleModel *Article) Create() {
	database.DB.Create(&articleModel)
}

func (articleModel *Article) Save() (rowsAffected int64) {
	result := database.DB.Save(&articleModel)
	return result.RowsAffected
}
